
function selectSupplier(supplier_id){
	
	var url = '/storage/manager/pages/supplier.do?method=selectSupplier&d=' + new Date();
	url = url + '&supplier_id='+supplier_id;
	
	$.getJSON(url, {}, function(data){
		var supplier_id = document.getElementById('supplier_id');
		var supplier_name = document.getElementById('supplier_name');
		var supplier_man = document.getElementById('supplier_man');
		var supplier_phone = document.getElementById('supplier_phone');
		var supplier_fax = document.getElementById('supplier_fax');
		var supplier_address = document.getElementById('supplier_address');
		var supplier_comment_arr = document.getElementsByName('supplier_comment');
		var supplier_type_arr = document.getElementsByName('supplier_type');
		
		setTimeout(function (){
			supplier_id.value = data[0][0];
			supplier_name.value = data[0][1];
			supplier_man.value = data[0][2];
			supplier_phone.value = data[0][3];
			supplier_fax.value = data[0][4];
			supplier_address.value = data[0][5];
			
			var supplier_comment_val = '';
			for(var i=0;i<supplier_comment_arr.length;i++){
				if(supplier_comment_arr[i].value==data[0][6]){
					supplier_comment_arr[i].checked = true;
					break;
				}
			}
			var supplier_type_val = '';
			for(var i=0;i<supplier_type_arr.length;i++){
				if(supplier_type_arr[i].value==data[0][7]){
					supplier_type_arr[i].checked = true;
					break;
				}
			}
		},500);
	});
};
function saveOrUpdate(){
	var supplier_id_val = document.getElementById('supplier_id').value;
	
	var isFull = true;
	
	if(isFull){
		supplier_id_val==''?save():update();
	}else{
		alert('必要信息不完整');
	}
};
function save(){
	var supplier_id_val = escape(escape(document.getElementById('supplier_id').value));
	var supplier_name_val = escape(escape(document.getElementById('supplier_name').value));
	var supplier_man_val = escape(escape(document.getElementById('supplier_man').value));
	var supplier_phone_val = escape(escape(document.getElementById('supplier_phone').value));
	var supplier_fax_val = escape(escape(document.getElementById('supplier_fax').value));
	var supplier_address_val = escape(escape(document.getElementById('supplier_address').value));
	var supplier_comment_arr = document.getElementsByName('supplier_comment');
	var supplier_type_arr = document.getElementsByName('supplier_type');
	var supplier_comment_val = '';
	for(var i=0;i<supplier_comment_arr.length;i++){
		if(supplier_comment_arr[i].checked){
			supplier_comment_val = supplier_comment_arr[i].value;
			break;
		}
	}
	var supplier_type_val = '';
	for(var i=0;i<supplier_type_arr.length;i++){
		if(supplier_type_arr[i].checked){
			supplier_type_val = supplier_type_arr[i].value;
			break;
		}
	}
	
	var url = '/storage/manager/pages/supplier.do?method=create&d=' + new Date();
	url = url + '&supplier_name_val='+supplier_name_val;
	url = url + '&supplier_man_val='+supplier_man_val;
	url = url + '&supplier_phone_val='+supplier_phone_val;
	url = url + '&supplier_fax_val='+supplier_fax_val;
	url = url + '&supplier_address_val='+supplier_address_val;
	url = url + '&supplier_comment_val='+supplier_comment_val;
	url = url + '&supplier_type_val='+supplier_type_val;
	
	$.getJSON(url, {}, function(data){
		if(data=="true"){
			alert("保存成功");
			window.close();
		}else{
			alert("保存失败");
		}
	});
};
function update(){
	var supplier_id_val = escape(escape(document.getElementById('supplier_id').value));
	var supplier_name_val = escape(escape(document.getElementById('supplier_name').value));
	var supplier_man_val = escape(escape(document.getElementById('supplier_man').value));
	var supplier_phone_val = escape(escape(document.getElementById('supplier_phone').value));
	var supplier_fax_val = escape(escape(document.getElementById('supplier_fax').value));
	var supplier_address_val = escape(escape(document.getElementById('supplier_address').value));
	var supplier_comment_arr = document.getElementsByName('supplier_comment');
	var supplier_type_arr = document.getElementsByName('supplier_type');
	var supplier_comment_val = '';
	for(var i=0;i<supplier_comment_arr.length;i++){
		if(supplier_comment_arr[i].checked){
			supplier_comment_val = supplier_comment_arr[i].value;
			break;
		}
	}
	var supplier_type_val = '';
	for(var i=0;i<supplier_type_arr.length;i++){
		if(supplier_type_arr[i].checked){
			supplier_type_val = supplier_type_arr[i].value;
			break;
		}
	}
	
	var url = '/storage/manager/pages/supplier.do?method=update&d=' + new Date();
	url = url + '&supplier_id_val='+supplier_id_val;
	url = url + '&supplier_name_val='+supplier_name_val;
	url = url + '&supplier_man_val='+supplier_man_val;
	url = url + '&supplier_phone_val='+supplier_phone_val;
	url = url + '&supplier_fax_val='+supplier_fax_val;
	url = url + '&supplier_address_val='+supplier_address_val;
	url = url + '&supplier_comment_val='+supplier_comment_val;
	url = url + '&supplier_type_val='+supplier_type_val;
	
	$.getJSON(url, {}, function(data){
		if(data=="true"){
			alert("更新成功");
			window.close();
		}else{
			alert("更新失败");
		}
	});
};